package xrpool

import (
	"context"
	"github.com/gogf/gf/v2/os/glog"
	"github.com/gogf/gf/v2/os/grpool"
	"xr-game-server/core/cfg"
	"xr-game-server/core/constants/common"
)

var pool *grpool.Pool

func Init() {
	if cfg.GoPoolCfgModel.Size == common.Zero {
		pool = grpool.New(1024)
	} else {
		pool = grpool.New(cfg.GoPoolCfgModel.Size)
	}
}

// GetGoPool 防止go 过多,消耗内存

func AddWithRecover(ctx context.Context, userFunc grpool.Func) {
	pool.AddWithRecover(ctx, userFunc, func(ctx context.Context, exception error) {
		glog.Errorf(ctx, "协程池发生错误 %v", exception)
	})
}
